Ext.onReady(function() {
	var toolbar = Ext.create('Ext.toolbar.Toolbar', {
		dock : 'top',
		items : [ {
			text : '返回',
			xtype : 'button',
			listeners:{
				click: function(){
					location.href = "workMgr/flight_line_mgr";
				}
			}
		},{
			text : '刷新',
			xtype : 'button',
			listeners:{
				click: function(){
					Ext.getCmp("flight_angle_grid").getStore().reload();
				}
			}
		}]
	});
	
	var store = Ext.create('Ext.data.Store', {
	    fields:['Id', 'No', 'Ice', 'CornerAngle', 'GroundingType', 'Resistance'],
	    pageSize: 25,
	    autoLoad:true,
	    proxy: {
	        type: 'ajax',
	        url: '/flight_angle/'+flightLineId,
	        reader: {
	            type: 'json',
	            root: 'data.rows',
	            totalProperty: 'data.total'
	        }
	    }
	});
	
	var grid = Ext.create('Ext.grid.Panel', {
		id: "flight_angle_grid",
		store: store,
		columns : [{
			text : '杆塔编号',
			dataIndex : 'No'
		}, {
			text : '冰',
			dataIndex : 'Ice'
		}, {
			text : '转角角度',
			dataIndex : 'CornerAngle'
		}, {
			text : '接地型式',
			dataIndex : 'GroundingType'
		}, {
			text : '电阻',
			dataIndex : 'Resistance',
			flex:1
		}],
		bbar : Ext.create('Ext.PagingToolbar', {
			store : store,
			border: false,
			displayInfo : true,
			displayMsg : '显示{0} - {1} / 总数 {2}',
			emptyMsg : "没数据"
		})
	});
	
	var ice = Ext.create('Ext.form.field.Text', {
		id : 'Ice',
		name : 'Ice',
		labelWidth : 20,
		width:100,
		fieldLabel : '冰'
	});
	
	var cornerAngle = Ext.create('Ext.form.field.Text', {
		id : 'CornerAngle',
		margin: '0 5',
		name : 'CornerAngle',
		labelWidth : 60,
		width:150,
		fieldLabel : '转角角度'
	});
	
	
	var resistance = Ext.create('Ext.form.field.Text', {
		id : 'Resistance',
		name : 'Resistance',
		margin: '0 5',
		labelWidth : 30,
		width:100,
		fieldLabel : '电阻'
	});
	
	var groundingType = Ext.create('Ext.form.field.Text', {
		id : 'GroundingType',
		name : 'GroundingType',
		margin: '0 5',
		labelWidth : 60,
		width:150,
		fieldLabel : '接地型式'
	});
	
	var searchButton = Ext.create('Ext.Button', {
		text : '搜索',
		listeners:{
			click: function(){
				var store = Ext.getCmp("flight_angle_grid").getStore();
				store.removeAll();
				var Ice = Ext.isEmpty(Ext.getCmp("Ice").getValue()) ? '' : Ext.getCmp("Ice").getValue();
				var CornerAngle = Ext.isEmpty( Ext.getCmp("CornerAngle").getValue()) ? '' :  Ext.getCmp("CornerAngle").getValue();
				var Resistance = Ext.isEmpty( Ext.getCmp("Resistance").getValue()) ? 0  :  Ext.getCmp("Resistance").getValue();
				var GroundingType = Ext.isEmpty(Ext.getCmp("GroundingType").getValue()) ? '': Ext.getCmp("GroundingType").getValue();
				Ext.Ajax.request({
					url : '/flight_angle/searchFlightAngle/',
					params : {
						'Ice' : Ice,
						'CornerAngle' : CornerAngle ,
						'Resistance' : Resistance,
						'GroundingType' :GroundingType
					},
					callback : function(options, success, response) {
						if (success) {
							var result = Ext.decode(response.responseText);
							if (result.success) 
							{
								if(!Ext.isEmpty(result.data))
								{
									store.add(result.data.rows);
								}
							}
						}
					}
				})
			}
		}
	});
	
	var searchPanel = Ext.create('Ext.panel.Panel', {
		border : false,
		bodyBorder : false,
		layout : 'hbox',
		margin : '0 0 5 0',
		items : [ice, cornerAngle, resistance, groundingType, searchButton]
	});
	
	var panel = Ext.create("Ext.panel.Panel", {
		title: '',
		border : false,
		bodyBorder : false,
		layout : 'fit',
		dockedItems : [ toolbar ],
		items : [ Ext.create('Ext.container.Container', {
			margin: '5 5',
			items : [searchPanel, grid ]
		})]
	});
	Ext.create('Ext.Viewport', {
		layout : 'fit',
		style : 'background:none;background-color:white;',
		items : [ panel ]
	});
});